'// ========================================================================= '
'// ------------------------------------------------------------------------- '
'//!				\file		CSett.vb
'			        \date		june 2010
'			        \author		TNick
'
'			        \brief		
'
'
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'   This file is considered universal knowledge. No restrictions
'   are imposed; use as you see fit.
'   Please read ReadMe.txt and Licence.txt in root folder
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
'   
'
'// ------------------------------------------------------------------------- '
'// ========================================================================= '
'//
'//
'//
'//
'//  IMPORTS     ------------------------------------------------------------ '
#Region "Imports"

Imports System
Imports Microsoft.Win32

#End Region
'//  IMPORTS     ============================================================ '
'//
'//
'//
'//
'//  DEFINITIONS    --------------------------------------------------------- '


'//  DEFINITIONS    ========================================================= '
'//
'//
'//
'//
'//  DATA    ---------------------------------------------------------------- '


'//  DATA    ================================================================ '
'//
'//
'//
'//
'//  CLASS    --------------------------------------------------------------- '
Public Class CSett

    '// --------------------------------------------------------------------- '
    '// DATA



    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    '// Initailization of the settings
    Public Shared Sub Init
        '// as we're using the registry, no initialization is needed; if
        '// option for using a file will be given, code to open the file
        '// should go here
    End Sub
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// save a string setting value
    '// @param sApName    - the application                                                         '
    '// @param sValName   - the name
    '// @param sVal       - the value
    Public Shared Sub SaveStg( _
     ByRef sApName As String, _
     ByVal sValName As String, _
     ByVal sVal As String)


        Dim regSubAppK As RegistryKey = Nothing
        Try
            Try
                regSubAppK = CApp.regAppAddInKey.OpenSubKey(sApName, True)
            Finally
                If regSubAppK Is Nothing Then regSubAppK = CApp.regAppAddInKey.CreateSubKey(sApName)
            End Try
            If (sVal Is Nothing) Then
                sVal = ""
            End If
            regSubAppK.SetValue(sValName, sVal, RegistryValueKind.String)

        Catch ex As System.Exception
            CMain.DebugException(ex)


        Finally
            If Not (regSubAppK Is Nothing) Then regSubAppK.Close()
        End Try
    End Sub
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// save a int setting value
    '// @param sApName    - the application                                                         '
    '// @param sValName   - the name
    '// @param sVal       - the value
    Public Shared Sub SaveStg( _
      ByRef sApName As String, _
      ByVal sValName As String, _
      ByVal sVal As Long)


        Dim regSubAppK As RegistryKey = Nothing
        Try
            Try
                regSubAppK = CApp.regAppAddInKey.OpenSubKey(sApName, True)
            Finally
                If regSubAppK Is Nothing Then regSubAppK = CApp.regAppAddInKey.CreateSubKey(sApName)
            End Try
            regSubAppK.SetValue(sValName, sVal, RegistryValueKind.DWord)

        Catch ex As System.Exception
            CMain.DebugException(ex)


        Finally
            If Not (regSubAppK Is Nothing) Then regSubAppK.Close()
        End Try
    End Sub
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// save a bool setting value
    '// @param sApName    - the application                                                         '
    '// @param sValName   - the name
    '// @param sVal       - the value
    Public Shared Sub SaveStg( _
      ByRef sApName As String, _
      ByVal sValName As String, _
      ByVal sVal As Boolean)


        Dim regSubAppK As RegistryKey = Nothing
        Try
            Try
                regSubAppK = CApp.regAppAddInKey.OpenSubKey(sApName, True)
            Finally
                If regSubAppK Is Nothing Then regSubAppK = CApp.regAppAddInKey.CreateSubKey(sApName)
            End Try
            regSubAppK.SetValue(sValName, sVal, RegistryValueKind.DWord)

        Catch ex As System.Exception
            CMain.DebugException(ex)


        Finally
            If Not (regSubAppK Is Nothing) Then regSubAppK.Close()
        End Try
    End Sub
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// save a double setting value
    '// @param sApName    - the application                                                         '
    '// @param sValName   - the name
    '// @param sVal       - the value
    Public Shared Sub SaveStg( _
     ByRef sApName As String, _
     ByVal sValName As String, _
     ByVal sVal As Double)


        Dim regSubAppK As RegistryKey = Nothing
        Try
            Try
                regSubAppK = CApp.regAppAddInKey.OpenSubKey(sApName, True)
            Finally
                If regSubAppK Is Nothing Then regSubAppK = CApp.regAppAddInKey.CreateSubKey(sApName)
            End Try
            regSubAppK.SetValue(sValName, sVal.ToString, RegistryValueKind.String)

        Catch ex As System.Exception
            CMain.DebugException(ex)


        Finally
            If Not (regSubAppK Is Nothing) Then regSubAppK.Close()
        End Try
    End Sub
    '// ===================================================================== '





    '// --------------------------------------------------------------------- '
    '// gets a int setting value
    '// @param sApName    - the application                                                         '
    '// @param sValName   - the value
    '// @param iDefVal    - default
    '// @return either the value of setting or default value
    Public Shared Function GetIntStg( _
     ByRef sApName As String, _
     ByRef sValName As String, _
     ByVal iDefVal As Integer) As Integer

        Dim iRetV As Integer
        Dim regSubAppK As RegistryKey = Nothing
        Try
            Try
                regSubAppK = CApp.regAppAddInKey.OpenSubKey(sApName, False)
            Finally
                If regSubAppK Is Nothing Then regSubAppK = CApp.regAppAddInKey.CreateSubKey(sApName)
            End Try
            If regSubAppK Is Nothing Then regSubAppK = CApp.regAppAddInKey.CreateSubKey(sApName)
            Try
                iRetV = Cint(regSubAppK.GetValue(sValName, iDefVal))
            Catch
                iRetV = iDefVal
            End Try

        Catch ex As System.Exception
            CMain.DebugException(ex)
            iRetV = iDefVal

        Finally
            If Not (regSubAppK Is Nothing) Then regSubAppK.Close()
            GC.Collect()
            GC.WaitForPendingFinalizers()
        End Try
        Return iRetV
    End Function
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// gets a long setting value
    '// @param sApName    - the application                                                         '
    '// @param sValName   - the value
    '// @param iDefVal    - default
    '// @return either the value of setting or default value
    Public Shared Function GetLongStg( _
     ByRef sApName As String, _
     ByRef sValName As String, _
     ByVal iDefVal As Long) As Long

        Dim iRetV As Long
        Dim regSubAppK As RegistryKey = Nothing
        Try
            Try
                regSubAppK = CApp.regAppAddInKey.OpenSubKey(sApName, False)
            Finally
                If regSubAppK Is Nothing Then regSubAppK = CApp.regAppAddInKey.CreateSubKey(sApName)
            End Try
            Try
                iRetV = CLng(regSubAppK.GetValue(sValName, iDefVal))
            Catch
                iRetV = iDefVal
            End Try

        Catch ex As System.Exception
            CMain.DebugException(ex)
            iRetV = iDefVal
        Finally
            If Not (regSubAppK Is Nothing) Then regSubAppK.Close()
            GC.Collect()
            GC.WaitForPendingFinalizers()
        End Try
        Return iRetV
    End Function
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// gets a string setting value
    '// @param sApName    - the application                                                         '
    '// @param sValName   - the value
    '// @param sDefVal    - default
    '// @return either the value of setting or default value
    Public Shared Function GetStrStg( _
       ByRef sApName As String, _
       ByRef sValName As String, _
       ByVal sDefVal As String) As String

        Dim sRetV As String
        Dim regSubAppK As RegistryKey = Nothing
        Try
            Try
                regSubAppK = CApp.regAppAddInKey.OpenSubKey(sApName, False)
            Finally
                If regSubAppK Is Nothing Then regSubAppK = CApp.regAppAddInKey.CreateSubKey(sApName)
            End Try
            Try
                sRetV = regSubAppK.GetValue(sValName, sDefVal).ToString()
            Catch
                sRetV = sDefVal
            End Try

        Catch ex As System.Exception
            CMain.DebugException(ex)
            sRetV = sDefVal

        Finally
            If Not (regSubAppK Is Nothing) Then regSubAppK.Close()
            GC.Collect()
            GC.WaitForPendingFinalizers()
        End Try
        Return sRetV
    End Function
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    '// gets a double setting value
    '// @param sApName    - the application                                                         '
    '// @param sValName   - the value
    '// @param dDefVal    - default
    '// @return either the value of setting or default value
    Public Shared Function GetDblStg( _
       ByRef sApName As String, _
       ByRef sValName As String, _
       ByVal dDefVal As Double) As Double

        Dim dRetV As Double
        Dim regSubAppK As RegistryKey = Nothing
        Try
            Try
                regSubAppK = CApp.regAppAddInKey.OpenSubKey(sApName, False)
            Finally
                If regSubAppK Is Nothing Then regSubAppK = CApp.regAppAddInKey.CreateSubKey(sApName)
            End Try
            Try
                dRetV = CDbl(regSubAppK.GetValue(sValName, dDefVal.ToString))
            Catch
                dRetV = dDefVal
            End Try

        Catch ex As System.Exception
            CMain.DebugException(ex)
            dRetV = dDefVal

        Finally
            If Not (regSubAppK Is Nothing) Then regSubAppK.Close()
        End Try
        Return dRetV
    End Function
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    '// gets a boolean setting value
    '// @param sApName    - the application                                                         '
    '// @param sValName   - the value
    '// @param bDefVal    - default
    '// @return either the value of setting or default value
    Public Shared Function GetBolStg( _
      ByRef sApName As String, _
      ByRef sValName As String, _
      ByVal bDefVal As Boolean) As Boolean

        Dim bRetV As Boolean
        Dim regSubAppK As RegistryKey = Nothing
        Try
            Try
                regSubAppK = CApp.regAppAddInKey.OpenSubKey(sApName, False)
            Finally
                If regSubAppK Is Nothing Then regSubAppK = CApp.regAppAddInKey.CreateSubKey(sApName)
            End Try
            Try
                bRetV = CBool(regSubAppK.GetValue(sValName, bDefVal.ToString))
            Catch
                bRetV = bDefVal
            End Try

        Catch ex As System.Exception
            CMain.DebugException(ex)
            bRetV = bDefVal

        Finally
            If Not (regSubAppK Is Nothing) Then regSubAppK.Close()
        End Try
        Return bRetV
    End Function
    '// ===================================================================== '


End Class
'//  CLASS    =============================================================== '
'//
'//
'//
'//
'//  FUNCTIONS    ----------------------------------------------------------- '

'//  FUNCTIONS    =========================================================== '
'//
'//
'//
'//
'// ------------------------------------------------------------------------- '
'// ========================================================================= '



